
//Logic Input
//by Redo
//Uses a move map to capture keystrokes and send them to the server, for use with a keyboard or something

$LogicInput_Version = "1.1";

function LogicInput_Start(%mouse){
	if(!$LogicInput_Active){
		$LogicInput_Active = true;
		
		LogicInput_UpdateStopKey();
		
		LogicInput_MoveMap_Keys.push();
		if(%mouse) LogicInput_MoveMap_Axis.push();
		commandToServer('LInputStart');
		
		clientCmdBottomPrint("Logic Input is active. Press " @ $LogicInput_StopKey @ " to exit.", 3);
	}
}

function LogicInput_Stop(){
	if($LogicInput_Active){
		$LogicInput_Active = false;
		
		LogicInput_MoveMap_Keys.pop();
		LogicInput_MoveMap_Axis.pop();
		commandToServer('LInputStop');
		
		clientCmdBottomPrint("", 0.01);
	}
}

///////////////////////////////////////////////////////////
// Functions called on input from the movemaps

function LogicInput_SendKey(%key, %state){
	if(%state && (%key $= $LogicInput_StopKey)) {
		LogicInput_Stop();
	} else {
		commandToServer('LInputKey', %key, %state);
	}
}
function LogicInput_SendAxis(%axis, %amt) {
	commandToServer('LInputAxis', %axis, %amt);
}

///////////////////////////////////////////////////////////
// Client cmds

function clientCmdLStartInput(%mouse){
	LogicInput_Start(%mouse);
}
function clientCmdLStopInput(){
	LogicInput_Stop();
}
function clientCmdLInputHandshake() {
	commandToServer('LInputVersion', $LogicInput_Version);
}

///////////////////////////////////////////////////////////
// Remappable keybind for exiting input mode

if(!$LogicInput_MadeKeys) {
	$LogicInput_MadeKeys = 1;
	
	$remapDivision[$remapCount] = "Logic Input";
	$remapName    [$remapCount] = "Exit (Defaults to Esc)";
	$remapCmd     [$remapCount] = "LogicInput_Stop";
	$remapCount++;
}
function LogicInput_UpdateStopKey() {
	%key = getField(moveMap.getBinding("LogicInput_Stop"), 1);
	if(%key $= "") %key = "escape";
	$LogicInput_StopKey = %key;
}
LogicInput_UpdateStopKey();

///////////////////////////////////////////////////////////

LogicInput_Stop();

exec("./logicinputmovemap.cs");

